import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { YingshishipinService } from './yingshishipin.service';
import { CreateYingshishipinDto } from './dto/create-yingshishipin.dto';
import { UpdateYingshishipinDto } from './dto/update-yingshishipin.dto';
import { Yingshishipin } from './entities/yingshishipin.entity';
import { SearchPagesDto } from './dto/search-pages.dto';

@Controller('/admin/yingshishipin')
export class YingshishipinController {
  constructor(private readonly yingshishipinService: YingshishipinService) {}

  // 创建新课程
  @Post()
  create(@Body() createDto: CreateYingshishipinDto) {
    return this.yingshishipinService.create(createDto);
  }

  // 分页查询（带搜索条件）
  @Post('/page')
  findAllPage(@Body() pages: SearchPagesDto) {
    return this.yingshishipinService.findAllPage(pages);
  }

  // 批量删除
  @Post('/deleteList')
  deleteList(@Body() data: { list: Yingshishipin[] }) {
    return this.yingshishipinService.batchRemove(
      data.list.map((item) => item.id),
    );
  }

  // 获取全部数据
  @Get('yingshishipin_tj_leibie')
  statistics() {
    return this.yingshishipinService.statistics();
  }

  // 获取全部数据
  @Get()
  findAll() {
    return this.yingshishipinService.findAll();
  }

  // 获取单条详情
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.yingshishipinService.findOne(+id);
  }

  // 更新数据
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateDto: UpdateYingshishipinDto) {
    return this.yingshishipinService.update(+id, updateDto);
  }

  // 删除单条
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.yingshishipinService.remove(+id);
  }
}
